#ifndef __COMMONDATA_H__
#define __COMMONDATA_H__
#include "Data.h"
#include "cocos2d.h"
USING_NS_CC;

namespace suta
{
	class BallData:public Data,public CCLayer
	{
	public:
		bool init()
		{
			bool ret=false;
			do 
			{
				CC_BREAK_IF(!CCLayer::init());

				setType(BALL);
				setContentSize(CCSizeMake(30,30));
				setIsRelativeAnchorPoint(true);
				{
					CCSprite*center=CCSprite::spriteWithFile("ball.png");
					center->setPosition(ccp(15,15));
					addChild(center);
				}
				ret=true;
			} while (0);
			return ret;
		};
		LAYER_NODE_FUNC(BallData);
	};//class BallData

	class TargetData:public Data,public CCLayer
	{
	public:
		bool init()
		{
			bool ret=false;
			do 
			{
				CC_BREAK_IF(!CCLayer::init());

				setType(TARGET);
				setContentSize(CCSizeMake(30,30));
				setIsRelativeAnchorPoint(true);
				
				CCSprite*sprite=CCSprite::spriteWithFile("target.png");
				sprite->setPosition(ccp(15,15));
				addChild(sprite);
				ret=true;
			} while (0);
			return ret;
		};
		LAYER_NODE_FUNC(TargetData);
	};//class TargetData

	class StarData:public Data,public CCLayer
	{
	public:
		bool init()
		{
			bool ret=false;
			do 
			{
				CC_BREAK_IF(!CCLayer::init());

				setType(STAR);
				setContentSize(CCSizeMake(30,30));
				setIsRelativeAnchorPoint(true);
				{
					CCSprite*center=CCSprite::spriteWithFile("star.png");
					center->setPosition(ccp(15,15));
					addChild(center);
					
					CCMutableArray<CCSpriteFrame*>frames;
					CCSpriteFrame*frame1=CCSpriteFrame::frameWithTexture(CCTextureCache::sharedTextureCache()->addImage("star.png"),CCRectMake(0,0,30,30));
					CCSpriteFrame*frame2=CCSpriteFrame::frameWithTexture(CCTextureCache::sharedTextureCache()->addImage("star_l.png"),CCRectMake(0,0,30,30));
					
					frames.addObject(frame1);
					frames.addObject(frame2);

					CCAnimation*animation=CCAnimation::animationWithFrames(&frames,1.0f);

					CCAnimate*animate=CCAnimate::actionWithAnimation(animation);
					
					CCRepeatForever*repeat=CCRepeatForever::actionWithAction(animate);
					center->runAction(repeat);
				}
				ret=true;
			} while (0);
			return ret;
		};
		LAYER_NODE_FUNC(StarData);
	};//class StarData

	class IncrData:public Data,public CCLayer
	{
		int m_iNum;
	public:
		bool init(int num)
		{
			bool ret=false;
			do 
			{
				CC_BREAK_IF(!CCLayer::init());

				CCAssert(num>0,"Num in INCR must be greater than 0!");

				setType(INCR);
				m_iNum=num;
				setContentSize(CCSizeMake(30,30));
				setIsRelativeAnchorPoint(true);
				{
					CCSprite*center=CCSprite::spriteWithFile("incr.png");
					center->setPosition(ccp(15,15));
					addChild(center);
				}
				{
					char str[2]={0};
					SPRINTF(str,2,"%d",num);
					CCLabelBMFont*label=CCLabelBMFont::labelWithString(str,"fnt/menu.fnt");
					label->setPosition(ccp(15,15));
					addChild(label);
				}
				ret=true;
			} while (0);
			return ret;
		};
		LAYER_NODE_FUNC_PARAM(IncrData,int,num);

		inline int getNum(){return m_iNum;};
	};//class IncrData

	class WallData:public Data,public CCLayer
	{
	public:
		virtual bool init(CCSprite*sprite)
		{
			bool ret=false;
			do 
			{
				CC_BREAK_IF(!CCLayer::init());

				setType(WALL);
			
				setContentSize(sprite->getContentSize());
				setIsRelativeAnchorPoint(true);
				sprite->setPosition(ccp(getContentSize().width/2,getContentSize().height/2));
				addChild(sprite);
				ret=true;
			} while (0);
			return ret;
		};
		bool init(float width,float height)
		{
			bool ret=false;
			do 
			{
				CC_BREAK_IF(!CCLayer::init());

				setType(WALL);
				setContentSize(CCSizeMake(width,height));
				setIsRelativeAnchorPoint(true);
				{
					CCSprite*center=CCSprite::spriteWithFile("wall.png");
					center->setPosition(ccp(width/2,height/2));

					center->setScaleX(width/center->getContentSize().width);
					center->setScaleY(height/center->getContentSize().height);
					addChild(center);
				}
				ret=true;
			} while (0);
			return ret;
		};
		LAYER_NODE_FUNC_PARAM(WallData,CCSprite*,sprite);
		LAYER_NODE_FUNC_PARAM_2(WallData,float,width,float,height);
	};//class WallData


	class MenuData:public Data,public CCLayer
	{
	public:
		bool init(CCMenuItem*item)
		{
			bool ret=false;
			do 
			{
				CC_BREAK_IF(!CCLayer::init());
				setType(MENU);
				setContentSize(CCSizeMake(208,83));
				setIsRelativeAnchorPoint(true);
				CCMenu*menu=CCMenu::menuWithItem(item);
				menu->setPosition(ccp(getContentSize().width/2,getContentSize().height/2));
				addChild(menu);
				ret=true;
			} while (0);
			return ret;
		};
		LAYER_NODE_FUNC_PARAM(MenuData,CCMenuItem*,item);
	};

}
#endif//__COMMONDATA_H__